package com.touch.client.forms;
import com.touch.client.ClientControls;
import com.touch.client.databank.SpriteBank;
import com.touch.core.NetConstants;
import com.touch.jgloo.owt.JGLAnimatedSprite;
import com.touch.jgloo.owt.JGLComponent;
import com.touch.jgloo.owt.JGLFrame;
import com.touch.jgloo.owt.JGLPane;
import com.touch.jgloo.owt.JGLButton;
import com.touch.jgloo.owt.JGLTextBox;
import com.touch.jgloo.owt.JGLLabel;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.KeyListener;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLEventListener;
public class NewCharacterGLEvents implements GLEventListener, MouseListener, KeyListener
{
	protected JGLFrame fNewCharacter;
	protected JGLPane pNewCharacter;
	protected JGLButton bMakeCharacter;
	protected JGLButton bCancel;
	protected JGLButton bGenerate;
	protected JGLTextBox tName;
	protected JGLLabel lName;	
	protected JGLLabel lStats;
	protected JGLLabel lStat1, lStat2, lStat3, lStat4, lHP, lMP, lSP;
	protected JGLLabel lStat1Val, lStat2Val, lStat3Val, lStat4Val, lHPVal, lMPVal, lSPVal;
	protected JGLAnimatedSprite charPlayer;
	
	public void setStats(int ... stats)
	{
		lStat1Val.setText("" + stats[0]);
		lStat2Val.setText("" + stats[1]);
		lStat3Val.setText("" + stats[2]);
		lStat4Val.setText("" + stats[3]);
		lHPVal.setText("" + stats[4]);
		lMPVal.setText("" + stats[5]);
		lSPVal.setText("" + stats[6]);
	}	
	public void display(GLAutoDrawable drawable) 
	{
		//draw the form and its components.
		this.fNewCharacter.render();
		this.charPlayer.render();
	}

	
	public void displayChanged(GLAutoDrawable arg0, boolean arg1, boolean arg2) {}

	
	public void init(GLAutoDrawable drawable)
	{									
		System.out.println(SpriteBank.SPRITE.size());
		this.charPlayer = SpriteBank.SPRITE.elementAt(1).clone();
		this.charPlayer.setState("walk-down");
		this.charPlayer.setIsAnimation(true);
		
		//create all the objects
		this.fNewCharacter = new JGLFrame("New Character", 320, 300);
		this.bCancel = new JGLButton("Cancel", 120, 25);
		this.bMakeCharacter = new JGLButton("Create", 120, 25);
		this.bGenerate = new JGLButton("Generate", 120, 25);
		this.tName = new JGLTextBox(120, "          ");
		this.pNewCharacter = new JGLPane(96, 96);		
		this.lName = new JGLLabel("Name");		
						
		this.lStats = new JGLLabel("Stats");
		this.lHP = new JGLLabel("HP:");
		this.lMP = new JGLLabel("MP:");
		this.lSP = new JGLLabel("SP:");
		this.lStat1 = new JGLLabel("STR:");
		this.lStat2 = new JGLLabel("DEX:");
		this.lStat3 = new JGLLabel("INT:");
		this.lStat4 = new JGLLabel("SPT:");
		this.lStat1Val = new JGLLabel("5");
		this.lStat2Val = new JGLLabel("5");
		this.lStat3Val = new JGLLabel("5");
		this.lStat4Val = new JGLLabel("5");
		this.lHPVal = new JGLLabel("50");
		this.lMPVal = new JGLLabel("50");
		this.lSPVal = new JGLLabel("50");
		
		//add all the objects to the form
		this.fNewCharacter.add(this.bCancel);
		this.fNewCharacter.add(this.bMakeCharacter);
		this.fNewCharacter.add(this.tName);
		this.fNewCharacter.add(this.pNewCharacter);
		this.fNewCharacter.add(this.lStats);
		this.fNewCharacter.add(this.lName);	
		this.fNewCharacter.add(this.lHP);
		this.fNewCharacter.add(this.lHPVal);
		this.fNewCharacter.add(this.lMP);
		this.fNewCharacter.add(this.lMPVal);
		this.fNewCharacter.add(this.lSP);
		this.fNewCharacter.add(this.lSPVal);
		this.fNewCharacter.add(this.lStat1);
		this.fNewCharacter.add(this.lStat1Val);
		this.fNewCharacter.add(this.lStat2);
		this.fNewCharacter.add(this.lStat2Val);
		this.fNewCharacter.add(this.lStat3);
		this.fNewCharacter.add(this.lStat3Val);
		this.fNewCharacter.add(this.lStat4);
		this.fNewCharacter.add(this.lStat4Val);
		this.fNewCharacter.add(this.bGenerate);
				
		
		//move all of the objects
		this.bCancel.setPosition(175, 270, 0);
		this.bMakeCharacter.setPosition(30, 270, 0);
		this.lName.setPosition(30, 30, 0);
		this.tName.setPosition(120, 30, 0);
		this.pNewCharacter.setPosition(30, 60, 0);
		this.lStats.setPosition(175, 60, 0);	
		this.lHP.setPosition(200, 80, 0);	
		this.lHPVal.setPosition(250, 80, 0);
		this.lMP.setPosition(200, 100, 0);
		this.lMPVal.setPosition(250, 100, 0);
		this.lSP.setPosition(200, 120, 0);
		this.lSPVal.setPosition(250, 120, 0);
		this.lStat1.setPosition(200, 140, 0);
		this.lStat1Val.setPosition(250, 140, 0);
		this.lStat2.setPosition(200, 160, 0);
		this.lStat2Val.setPosition(250, 160, 0);
		this.lStat3.setPosition(200, 180, 0);
		this.lStat3Val.setPosition(250, 180, 0);
		this.lStat4.setPosition(200, 200, 0);
		this.lStat4Val.setPosition(250, 200, 0);
		this.bGenerate.setPosition(175, 220, 0);
		
		this.fNewCharacter.setVisible(true);
	}

	
	public void reshape(GLAutoDrawable arg0, int arg1, int arg2, int arg3, int arg4) {}

	
	public void mouseClicked(MouseEvent e) 
	{	
		//fire the mouse events
		this.fNewCharacter.mouseClicked(e);		
		this.bCancel.mouseClicked(e);
		this.bGenerate.mouseClicked(e);
		this.bMakeCharacter.mouseClicked(e);
		this.pNewCharacter.mouseClicked(e);
		this.tName.mouseClicked(e);
		
		if(JGLComponent.getSelected() == this.bGenerate.getIndex())
		{
			ClientControls.CLIENT_SOCKET.send(NetConstants.RANDOMIZE_STATS);
		}
	}

	
	public void mouseEntered(MouseEvent e){}
	
	public void mouseExited(MouseEvent e) {}
	
	public void mousePressed(MouseEvent e) 
	{	
		//fire the form MousePressed event for moving the frame and stuff.
		this.fNewCharacter.mousePressed(e);
	}
	
	public void mouseReleased(MouseEvent e) 
	{	
		//fire the form mouseReleased event for moving the frame.
		this.fNewCharacter.mouseReleased(e);
	}
	
	public void keyPressed(KeyEvent e) 
	{
		//used for typing.
		this.tName.keyPressed(e);
	}
	
	public void keyReleased(KeyEvent e) 
	{	
		//used for typing.
		this.tName.keyReleased(e);
	}
	
	public void keyTyped(KeyEvent e) 
	{	
		//used for typing
		this.tName.keyTyped(e);
	}

}
